import { getById, getPage, saveOrUpdate, deleteByIds } from '@/api/ms/member/student'

const getDefaultState = () => {
  return {
    studentBasicPage: {
      pageInfo: {
        pageNum: 1,
        pageSize: 10,
        pageCount: 50,
        total: 500
      },
      list: [
        {
          stuNo: '20230402326',
          realName: 'o16',
          gender: '男',
          dateOfBirth: '2023-03-16',
          idCardType: 111,
          idCardNumber: '910419872566184151',
          photoUrl: 'http://foobar.com/7us2w24gwx',
          idCardTypeShow: '居民身份证'
        }
      ]
    },
    studentInfo: {
      id: 1,
      stuNo: '20190102',
      realName: '李伊美',
      gender: '女',
      dateOfBirth: '2001-05-15',
      idCardType: 111,
      idCardTypeShow: '居民身份证',
      idCardNumber: '65458955415',
      photoUrl: 'http://285.com',
      classId: 17,
      classNameShow: '待填充班级',
      classOrder: 285,
      dateOfAdmission: '2023-03-16',
      dateOfGraduation: '2023-03-16',
      schoolSystem: 4,
      collegeId: 11,
      collegeNameShow: '待填充学院',
      majorId: 1,
      majorNameShow: '待填充专业',
      degree: 1,
      degreeShow: '学硕',
      currentStatus: 1,
      currentStatusShow: '退学',
      phoneNum: '13452212125',
      email: '123@qq.com',
      address: '浙江省杭州市',
      qqNumber: '3335482425',
      wechatNumber: 'vx58882009',
      workAddress: null
    }
  }
}

const state = getDefaultState()

const mutations = {
  SET_STUDENT_BASIC_PAGE: (state, studentBasicPage) => {
    state.studentBasicPage = studentBasicPage
  },
  SET_STUDENT_INFO: (state, studentInfo) => {
    state.studentInfo = studentInfo
  }
}

const actions = {
  getTablePage({ commit }, param) {
    return new Promise((resolve, reject) => {
      getPage(param).then((res) => {
        const { pageInfo, list } = res
        const data = { pageInfo, list }
        commit('SET_STUDENT_BASIC_PAGE', data)
        resolve(data)
      }).catch((err) => {
        reject(err)
      })
    })
  },
  getById({ commit }, param) {
    return new Promise((resolve, reject) => {
      getById(param).then(({ data }) => {
        commit('SET_STUDENT_INFO', data)
        resolve(data)
      }).catch((err) => {
        reject(err)
      })
    })
  },
  saveOrUpdate({ commit }, reqBody) {
    return new Promise((resolve, reject) => {
      saveOrUpdate(reqBody).then(({ message }) => {
        resolve(message)
      }).catch((err) => {
        reject(err)
      })
    })
  },
  deleteByIds({ commit }, reqBody) {
    /**
     [1,2,3]
     */
    return new Promise((resolve, reject) => {
      deleteByIds(reqBody).then(({ message }) => {
        resolve(message)
      }).catch((err) => {
        reject(err)
      })
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
